package com.hdaccp.ch08

import org.apache.spark.sql.{SaveMode, SparkSession}

/**
  *   .txt -> parquet
  */
object Demo {
  def main(args: Array[String]): Unit = {
      val spark = SparkSession.builder()
      .master("local[2]")
      .appName("ch08DemoAppp")
        .getOrCreate()

    import spark.implicits._

    val rdd = spark.sparkContext.textFile("F:\\accp教学\\sparkresources\\music1.txt")

    val df = rdd.map(x=>x.split("\t")).map(y=>Music(y(0),y(1),y(2),y(3),y(4),y(5))).toDF()

    df.coalesce(1).write.format("parquet").partitionBy("gender").mode(SaveMode.Overwrite).save("F:\\accp教学\\sparkresources\\clean12")


    spark.stop()
  }
}
